package tk.hoopy.zedtown.input;

import java.awt.Point;

import tk.hoopy.zedtown.graphics.GameWindow;

public class InputManager {
	
	KeyboardInput keyboardInput = new KeyboardInput();
	MouseInput mouseInput = new MouseInput();
	GameWindow gameWindow;
	
	public InputManager(GameWindow gamewindow) {
		gameWindow = gamewindow;
		gameWindow.addKeyListener(keyboardInput);
		gameWindow.addMouseListener(mouseInput);
	}
	
	//Keyboard
	
	public boolean GetKeyState(int key) {
		return keyboardInput.GetKeyState(key);
	}
	
	//Mouse
	
	public boolean newClickEvent(int mouseButton) {
		return mouseInput.newClickEvent(mouseButton);
	}
	
	public boolean newPressEvent(int mouseButton) {
		return mouseInput.newPressEvent(mouseButton);
	}
	
	public boolean newReleaseEvent(int mouseButton) {
		return mouseInput.newReleaseEvent(mouseButton);
	}
	
	public Point buttonPressed(int mouseButton) {
		Point mousePosition = new Point();
		mousePosition.setLocation(
				mouseInput.buttonPressed(mouseButton).getX() - gameWindow.getLocationOnScreen().getX(),
				mouseInput.buttonPressed(mouseButton).getY() - gameWindow.getLocationOnScreen().getY()
				);
		return mousePosition;
	}
	
	public Point buttonClicked(int mouseButton) {
		Point mousePosition = new Point();
		mousePosition.setLocation(
				mouseInput.buttonClicked(mouseButton).getX() - gameWindow.getLocationOnScreen().getX(),
				mouseInput.buttonClicked(mouseButton).getY() - gameWindow.getLocationOnScreen().getY()
				);
		return mousePosition;
	}
	
	public int GetMousePositionX() {
		return (int) (mouseInput.GetMousePositionX() - gameWindow.getLocationOnScreen().getX());
	}
	
	public int GetMousePositionY() {
		return (int) (mouseInput.GetMousePositionY() - gameWindow.getLocationOnScreen().getY());
	}
	
}
